Fixes early destruction of IAsyncEnumerable<T>
sent as return value from RPC methods
#1004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In certain scenarios, there may have also been effectively a memory leak that this also fixes.
Fixes #999
This pull request primarily involves changes to the
src/StreamJsonRpc/Reflection/MessageFormatterEnumerableTracker.cs
file and thetest/StreamJsonRpc.Tests/AsyncEnumerableTests.cs
file. The changes aim to improve the tracking of outbound request IDs and their correspondingIAsyncEnumerable<T>
state machines, and to update the test cases to reflect these changes.Key changes include:
MessageFormatterEnumerableTracker.cs:
The dictionary used to map outbound request IDs has been updated to track the list of tokens that represent
IAsyncEnumerable<T>
state machines it owns. This ensures that the state machines are cleaned up after receiving the final response.The
GetToken<T>(IAsyncEnumerable<T> enumerable)
method has been updated to only track the token if it is serializing a request. This prevents outbound responses that carry enumerables from being disposed of when an inbound response with the same ID is received.The
CleanUpResources(RequestId requestId)
method has been updated to clean up resources associated with outbound request IDs.AsyncEnumerableTests.cs:
The
AsyncEnumerableTests
class has been updated to include a newClient
object and aserverProxy
for theIClient
interface. [1] [2] [3] [4] [5] [6]A new test case
EnumerableIdDisposal()
has been added to test the disposal of enumerable IDs.The
Server
class has been updated to include aClient
property and a new methodCallbackClientAndYieldOneValueAsync(CancellationToken cancellationToken)
. [1] [2]A new
Client
class has been added to implement theIClient
interface.